/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package kks;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import javax.swing.*;

/**
 *
 * @author basti
 */
public class ToolbarMainMenu extends JToolBar{
    
    private JButton btnToolBarHome;
    private JButton btnToolBarSpecial;
    private JButton btnToolBarTickets;
    private JButton btnToolBarFood;
    private JButton btnToolBarLogout;
    private PanelSeats pnlSeats;
    private ActionListener listenerPanels;
    private HomeFrame homeFrame;
    private ArrayList<JButton> btnList;
    private JComboBox cbDate;


    ToolbarMainMenu(HomeFrame frame)
    {
        //Toolbar options
        setFloatable(false);
        setBackground(CustomColors.BackgroundLight);
        homeFrame = frame;
        //setPreferredSize(new Dimension(100, 32));
        
        //home button
        btnToolBarHome = new JButton("Home");
        btnToolBarHome.setFocusable(false);
        btnToolBarHome.setHorizontalTextPosition(SwingConstants.CENTER);
        btnToolBarHome.setVerticalTextPosition(SwingConstants.BOTTOM);        
        btnToolBarHome.setIcon(new ImageIcon(getClass().getResource("/images/icons/cottage-64.png")));
        btnToolBarHome.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                homeFrame.setPanelMoviesVisible(true);                
            }
        });
        add(btnToolBarHome);
    
        btnToolBarTickets = new JButton("Tickets");
        btnToolBarTickets.setFocusable(false);
        btnToolBarTickets.setHorizontalTextPosition(SwingConstants.CENTER);
        btnToolBarTickets.setVerticalTextPosition(SwingConstants.BOTTOM);        
        btnToolBarTickets.setIcon(new ImageIcon(getClass().getResource("/images/icons/ticket-64.png")));
        btnToolBarTickets.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                //homeFrame.setPanelMoviesVisible(false);
                //homeFrame.setPanelSeatsVisible(true, 10,10);
            }
        });
        add(btnToolBarTickets);
        
        btnToolBarFood = new JButton("Food");
        btnToolBarFood.setFocusable(false);
        btnToolBarFood.setHorizontalTextPosition(SwingConstants.CENTER);
        btnToolBarFood.setVerticalTextPosition(SwingConstants.BOTTOM);        
        btnToolBarFood.setIcon(new ImageIcon(getClass().getResource("/images/icons/fork-64.png")));
        add(btnToolBarFood);
        
        btnToolBarSpecial = new JButton("Special");
        btnToolBarSpecial.setFocusable(false);
        btnToolBarSpecial.setHorizontalTextPosition(SwingConstants.CENTER);
        btnToolBarSpecial.setVerticalTextPosition(SwingConstants.BOTTOM);        
        btnToolBarSpecial.setIcon(new ImageIcon(getClass().getResource("/images/icons/star-64.png")));
        add(btnToolBarSpecial);

        btnList = new ArrayList<>();
        cbDate = new JComboBox();
        cbDate.setFont(CustomFonts.FontDate);
        
        for (int i = 0; i < 14; i++)
        {
            cbDate.addItem(dateToButtons(i));
        }
        
       for (int i = 0; i < 2; i++)
        {         
            btnList.add(new JButton(dateToButtons(i)));  
            btnList.get(i).setFocusable(false);
            btnList.get(i).setFont(CustomFonts.FontDate);
        }     
       add(cbDate);
        
        
        btnToolBarLogout = new JButton("Logout");
        btnToolBarLogout.setFocusable(false);
        btnToolBarLogout.setAlignmentX(JToolBar.EAST);
        btnToolBarLogout.setHorizontalTextPosition(SwingConstants.CENTER);
        btnToolBarLogout.setVerticalTextPosition(SwingConstants.BOTTOM);        
        btnToolBarLogout.setIcon(new ImageIcon(getClass().getResource("/images/icons/key-64.png")));
        add(btnToolBarLogout);
        
       
    }
    
    private String dateToButtons(int day)
    {
        Calendar cal = Calendar.getInstance();
        DateFormat df = DateFormat.getDateInstance(DateFormat.FULL);
        cal.add(cal.DATE, day);
        
        String s = df.format(cal.getTime());
        
        switch (day)
        {
            case 0:
                {
                    s = "today";
                    break;
                }
            case 1:
                {
                    s = "tomorrow";
                    break;
                }
        }
        
        return s;
    }
    
    public void setSelectedButtonTicket(boolean isHighlighted)
    {
        if (isHighlighted)
            btnToolBarTickets.setBackground(CustomColors.MainColorLight);
        else
            btnToolBarTickets.setBackground(CustomColors.BackgroundLight);
    }
    
    public void setSelectedButton(boolean btnHome, boolean btnTicket, boolean btnFood, boolean btnSpecial)
    {
        if (btnHome)
        {
            btnToolBarHome.setBackground(CustomColors.MainColorLight);            
            btnToolBarTickets.setBackground(CustomColors.BackgroundLight);
            btnToolBarFood.setBackground(CustomColors.BackgroundLight);
            btnToolBarSpecial.setBackground(CustomColors.BackgroundLight);
        }
        
        if (btnTicket)
        {
            btnToolBarHome.setBackground(CustomColors.BackgroundLight);            
            btnToolBarTickets.setBackground(CustomColors.MainColorLight);
            btnToolBarFood.setBackground(CustomColors.BackgroundLight);
            btnToolBarSpecial.setBackground(CustomColors.BackgroundLight);
        }
        if (btnFood)
        {
            btnToolBarHome.setBackground(CustomColors.BackgroundLight);            
            btnToolBarTickets.setBackground(CustomColors.BackgroundLight);
            btnToolBarFood.setBackground(CustomColors.MainColorLight);
            btnToolBarSpecial.setBackground(CustomColors.BackgroundLight);
        }

        if (btnSpecial)
        {
            btnToolBarHome.setBackground(CustomColors.BackgroundLight);            
            btnToolBarTickets.setBackground(CustomColors.BackgroundLight);
            btnToolBarFood.setBackground(CustomColors.BackgroundLight);
            btnToolBarSpecial.setBackground(CustomColors.MainColorLight);
        }        
            
    }    
    
}
